﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HengTong.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class 路由表增加移动端路由增加通知分类待办增加业务ID : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "Route",
                table: "SysTodoCenter");

            migrationBuilder.RenameColumn(
                name: "Route",
                table: "SysBillRoute",
                newName: "PcRoute");

            migrationBuilder.AlterColumn<string>(
                name: "ApproveResult",
                table: "SysTodoCenter",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(max)",
                oldNullable: true);

            migrationBuilder.AddColumn<string>(
                name: "BusinessId",
                table: "SysTodoCenter",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "RouteId",
                table: "SysTodoCenter",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "MobileRoute",
                table: "SysBillRoute",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: true);

            migrationBuilder.CreateTable(
                name: "SysNotificationCategory",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
                    Code = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    Description = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
                    Icon = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    EnableInternalMessage = table.Column<bool>(type: "bit", nullable: false),
                    EnableSms = table.Column<bool>(type: "bit", nullable: false),
                    EnableEmail = table.Column<bool>(type: "bit", nullable: false),
                    EnableAppPush = table.Column<bool>(type: "bit", nullable: false),
                    EnableWechatPush = table.Column<bool>(type: "bit", nullable: false),
                    EnableDingTalkPush = table.Column<bool>(type: "bit", nullable: false),
                    DefaultPriority = table.Column<int>(type: "int", nullable: false),
                    IsEnabled = table.Column<bool>(type: "bit", nullable: false),
                    SortOrder = table.Column<int>(type: "int", nullable: false),
                    ParentId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysNotificationCategory", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysNotificationCategory_SysNotificationCategory_ParentId",
                        column: x => x.ParentId,
                        principalTable: "SysNotificationCategory",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateTable(
                name: "SysNotification",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Title = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: false),
                    Content = table.Column<string>(type: "nvarchar(4000)", maxLength: 4000, nullable: true),
                    Route = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
                    MobilRoute = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
                    CategoryId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    BusinessType = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    BusinessId = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    SenderId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    SenderName = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    ReceiverId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ReceiverName = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    Status = table.Column<int>(type: "int", nullable: false),
                    Priority = table.Column<int>(type: "int", nullable: false),
                    IsTop = table.Column<bool>(type: "bit", nullable: false),
                    SendTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    ReadTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysNotification", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysNotification_SysNotificationCategory_CategoryId",
                        column: x => x.CategoryId,
                        principalTable: "SysNotificationCategory",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateIndex(
                name: "IX_SysTodoCenter_RouteId",
                table: "SysTodoCenter",
                column: "RouteId");

            migrationBuilder.CreateIndex(
                name: "IX_SysNotification_CategoryId",
                table: "SysNotification",
                column: "CategoryId");

            migrationBuilder.CreateIndex(
                name: "IX_SysNotificationCategory_ParentId",
                table: "SysNotificationCategory",
                column: "ParentId");

            migrationBuilder.AddForeignKey(
                name: "FK_SysTodoCenter_SysBillRoute_RouteId",
                table: "SysTodoCenter",
                column: "RouteId",
                principalTable: "SysBillRoute",
                principalColumn: "ID");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SysTodoCenter_SysBillRoute_RouteId",
                table: "SysTodoCenter");

            migrationBuilder.DropTable(
                name: "SysNotification");

            migrationBuilder.DropTable(
                name: "SysNotificationCategory");

            migrationBuilder.DropIndex(
                name: "IX_SysTodoCenter_RouteId",
                table: "SysTodoCenter");

            migrationBuilder.DropColumn(
                name: "BusinessId",
                table: "SysTodoCenter");

            migrationBuilder.DropColumn(
                name: "RouteId",
                table: "SysTodoCenter");

            migrationBuilder.DropColumn(
                name: "MobileRoute",
                table: "SysBillRoute");

            migrationBuilder.RenameColumn(
                name: "PcRoute",
                table: "SysBillRoute",
                newName: "Route");

            migrationBuilder.AlterColumn<string>(
                name: "ApproveResult",
                table: "SysTodoCenter",
                type: "nvarchar(max)",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(128)",
                oldMaxLength: 128,
                oldNullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Route",
                table: "SysTodoCenter",
                type: "nvarchar(512)",
                maxLength: 512,
                nullable: true);
        }
    }
}
